    package com.itheima;
    import java.util.ArrayList;

    public class ArrayListDemo7Case {
        public static void main(String[] args) {
            //1.创建集合
            ArrayList<User> list = new ArrayList<User>();
            //2.创建三个用户对象
            User u1=new User("001","zhngsan","123");
            User u2=new User("002","li","456");
            User u3=new User("003","zhngsan","789");
       //3.添加元素
            list.add(u1);
            list.add(u2);
            list.add(u3);
            //4.调用方法看id是否存在
            int flag = contains(list, "002");
            if(flag>=0){
                User u = list.get(flag);
                System.out.println(u.getId());
            }else{
                System.out.println("不存在");
            }

        }
        public static int contains(ArrayList<User> list,String id){
            for (int i = 0; i < list.size(); i++) {
                if(list.get(i).getId().equals(id)){
                    return i;
                }
            }
            return -1;
        }
    }
